module.exports = app => {
    const { STRING, INTEGER, BOOLEAN } = app.Sequelize;

    const Admin = app.model.define(
        'admin',
        {
            username: {
                type: STRING(32),
                allowNull: false
            },
            password: {
                type: STRING(32),
                allowNull: false
            },
            type: {
                type: INTEGER,
                allowNull: false,
                defaultValue: 1
            },
            status: {
                type: BOOLEAN,
                allowNull: false,
                defaultValue: true
            },
            grant_type: {
                type: INTEGER,
                allowNull: false,
                defaultValue: 1
            },
            role_id: {
                type: INTEGER,
                allowNull: true
            },
            avatar: {
                type: STRING(255),
                allowNull: true
            },
            note: {
                type: STRING(255),
                allowNull: true
            },
        },
        {
            tableName: 'tbl_admin',
            timestamps: true,
            underscored: true,
            charset: 'utf8',
            collate: 'utf8_general_ci'
        });

    Admin.createTable = async () => {
        try {
            return await Admin.sync({force: true});
        } catch (error) {
            return error.message;
        }
    };

    return Admin;
};